#include "clickpathanimatecontrol.h"
#include <QTimer>
#include <QDebug>

ClickPathAnimateControl::ClickPathAnimateControl(double time, int diameter, bool radiant, double opacity)
{
    showTime = time * 1000;

    globalMouse = new GlobalMousePath();
    connect( globalMouse, SIGNAL( mousemove( int, int ) ), this, SLOT( mousemove( int, int ) ) );

    animateWindow = new AnimateWindowPath();
//    animateWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint /*| Qt::ToolTip*/ );
//    animateWindow->show();
    setDiameterColor( diameter, Qt::red );
    setRadiant(radiant);
    setOpacity(opacity);
}

ClickPathAnimateControl::~ClickPathAnimateControl()
{
}

void ClickPathAnimateControl::pointerOnOff( bool value )
{
    if ( value == true )
        animateWindowOn();

    if ( value == false )
        animateWindowOff();
}

void ClickPathAnimateControl::animateWindowOn()
{
    globalMouse->setCursorOn();
    globalMouse->mousePressed();
}

void ClickPathAnimateControl::animateWindowOff()
{
    globalMouse->setCursorOff();
}

void ClickPathAnimateControl::mousemove(int x, int y)
{
    animateWindow->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
    animateWindow->move( x - animateWindow->width() / 2, y - animateWindow->height() / 2);
    animateWindow->show();
    animateWindow->addTrailPoint(QPoint(x, y));

//    QTimer::singleShot( showTime, this, SLOT( closeWindow() ) );
}

void ClickPathAnimateControl::closeWindow()
{
    animateWindow->hide();
}

void ClickPathAnimateControl::setDiameterColor( int diameter, QColor color)
{
    animateWindow->setRadiusColor( diameter, color );
}

void ClickPathAnimateControl::setShowTime( double value )
{
    showTime = value * 1000;
}

void ClickPathAnimateControl::setOpacity( double value )
{
    animateWindow->setOpacity( value );
}

void ClickPathAnimateControl::setRadiant( bool value )
{
    animateWindow->setRadiant( value );
}
